package com.yanqu.road.server.cmd.cross.marriage;

import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.marriage.MarriageMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = Protocol.S_CROSS_MARRIAGE_CANCEL_RESP, desc = "跨服联姻取消响应")
public class CrossMarriageCancelRespCmd implements Command {
	@Override
	public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
		MarriageProto.MarriageApplyCancelRespMsg reqMsg = MarriageProto.MarriageApplyCancelRespMsg.parseFrom(packet.getBytes());
		int ret = reqMsg.getRet();
		String childUid = reqMsg.getChildUid();
		if(0 == ret || ret == GameErrorCode.E_MARRIAGE_CHILD_NO_FOUND){
			MarriageMgr.crossMarriageCancelResponse(packet.getPlayerId(), childUid);
			ret = 0;
		}
		MarriageProto.MarriageApplyCancelRespMsg.Builder respMsg = MarriageProto.MarriageApplyCancelRespMsg.newBuilder();
		respMsg.setRet(ret);
		GamePlayer player = GamePlayerMgr.getOnlinePlayer(packet.getPlayerId());
		if(null != player){
			player.sendPacket(Protocol.U_CROSS_MARRIAGE_APPLY_CANCEL, respMsg);
		}
	}
}
